<?php

class HomeController extends BaseController {

    /*
    |--------------------------------------------------------------------------
    | Default Home Controller
    |--------------------------------------------------------------------------
    |
    | You may wish to use controllers instead of, or in addition to, Closure
    | based routes. That's great! Here is an example controller method to
    | get you started. To route to this controller, just add the route:
    |
    |	Route::get('/', 'HomeController@showWelcome');
    |
    */

    public function index()
    {

//        echo imagesx($image_1);

        return Redirect::route('admin.login');
    }

    public function create(){
        $count = Template::where('state',0)->count();
        if($count != 0){
            $templates = Template::where('state',0)->get();
            foreach($templates as $template){
                if($template->type == 1){
                    $result = Template::template_work($template->id, $template->openid,$template->data1,$template->data2,$template->data3,$template->data4,$template->data5,$template->data6,$template->data7,$template->url);
                    var_dump($result);
                }
                if($template->type == 2){
                    $result = Template::template_complete($template->id, $template->openid,$template->data1,$template->data2,$template->data3,$template->data4,$template->url);
                    var_dump($result);
                }
                if($template->type == 3){
                    $result = Template::template_paidan($template->id, $template->openid,$template->data1,$template->data2,$template->data3,$template->data4,$template->data5,$template->data6,$template->data7,$template->url);
                    var_dump($result);
                }
                if($template->type == 4){
                    $result = Template::template_daoqi($template->id, $template->openid,$template->data1,$template->data2,$template->data3,$template->data4,$template->url);
                    var_dump($result);
                }
            }
        }
    }

    public function set_old_bangding(){
        $olds = Mount::where('type','old')->get();
        foreach($olds as $old ){
            if($old->bangding == ''){
                $bangding = $this->randStr(2).rand(100000,999999);
                $mount = Mount::find($old->id);
                $mount->bangding = $bangding;
                $mount->save();
            }
        }
    }

    public function randStr($i){
        $str = "abcdefghijklmnopqrstuvwxyz";
        $finalStr = "";
        for($j=0;$j<$i;$j++)
        {
            $finalStr .= substr($str,rand(0,25),1);
        }
        return $finalStr;
    }

    public function filter(){
        $filterins = Filterin::where('has_end','0')->get();
        foreach($filterins as $filterin){
            $end_time = $filterin->commodity->life*30*24*60*60+$filterin->start_time;
            $filterin = Filterin::find($filterin->id);
            $filterin->end_time = $end_time;
            $filterin->has_end = 1;
            $filterin->save();
        }
    }

    public function state_count(){
        //分销商粉丝数修正

//        $users = User::where('permissions','{"section":1}')->orderBy('province', 'ASC')->orderBy('city', 'ASC')->get();
//        foreach($users as $user){
//            $count = Customer::where('area',$user->area)->count();
//            $saveuser = User::find($user->id);
//            $saveuser->subscribe = $count;
//            $saveuser->save();
//        }
//        exit;

        //重置用户密码
//        // Find the user using the user email address
//        $user = Sentry::findUserByLogin('13601249208');
//
//        // Get the password reset code
//        $resetCode = $user->getResetPasswordCode();
//
//        $user = Sentry::findUserById(100);
//
//        // Check if the reset password code is valid
//        if ($user->checkResetPasswordCode($resetCode))
//        {
//            // Attempt to reset the user password
//            if ($user->attemptResetPassword($resetCode, 'beijing9208'))
//            {
//                // Password reset passed
//                echo 1;
//            }
//            else
//            {
//                // Password reset failed
//                echo 2;
//            }
//        }
//        else
//        {
//            // The provided password reset code is Invalid
//        }
//        exit;
        //重新生产邀请码
//        $customers = Customer::all();
//        foreach($customers as $customer){
//            $c = Customer::find($customer->id);
//            $new = $customer->id;
//            $new = sprintf('%06s', $new);
//
//        }
//        exit;

        //老客户导入
//        $orders = Order::all();
//        $i = 90000;
//        foreach($orders as $order){
//            if($order->tel != ''){
//                $arrad[] = array(
//                    'customer_id'=>0,
//                    'machine_id'=>8,
//                    'city'=>9,
//                    'area_id'=>0,
//                    'section_id'=>108,
//                    'code'=>$i,
//                    'mount_name'=>$order->un,
//                    'mount_mobile'=>$order->tel,
//                    'address'=>$order->address,
//                    'sex'=>1,
//                    'state'=>3,
//                    'type'=>'old',
//                );
//                $i++;
//            }
//        }
//        DB::beginTransaction();
//        DB::table('mounts')->insert($arrad);
//        DB::commit();
//        exit;


//        $orders = Order::all();
//        foreach($orders as $order){
//            if($order->tel != '') {
//                $mount = Mount::where('type', 'old')->where('mount_mobile', $order->tel)->first();
//                $mount->created_at = date('Y-m-d H:i:s', $order->btime);
//                $mount->save();
//            }
//        }
//        exit;


//        $mounts = Mount::where('id','>',2065)->where('type','old')->orderBy('id','asc')->get();
//        $i = 13001;
//        foreach($mounts as $mount){
//            $m = Mount::find($mount->id);
//            $m->code = $i;
//            $m->save();
//            $i++;
//        }


        $xiaoqus = Area::all();
        foreach($xiaoqus as $xiaoqu){
            $count = Mount::where('area_id',$xiaoqu->id)->where('state','>',0)->count();
            $savearea = Area::find($xiaoqu->id);
            $savearea->mount_count = $count;
            $savearea->save();
        }

        $users = User::where('permissions','{"section":1}')->orderBy('province', 'ASC')->orderBy('city', 'ASC')->get();
        foreach($users as $user){
            $count = Area::where('father_id',$user->area)->count();
            $count2 = Mount::where('section_id',$user->area)->where('state','>',0)->count();
//            $total = DB::table('areas')->sum('votes');
            $saveuser = User::find($user->id);
            $saveuser->mount_count = $count2;
            $saveuser->area_count = $count;
            $saveuser->save();
        }



        $customers = Customer::orderBy('id', 'ASC')->get();
        foreach($customers as $customer){
            $count = Mount::where('customer_id',$customer->id)->count();
//            $total = DB::table('areas')->sum('votes');
            $savecustomer = Customer::find($customer->id);
            $savecustomer->mount_count = $count;
            $savecustomer->save();
        }

    }

    public function filter_notice(){



        $filterins = Filterin::where('has_notice','0')->get();
        foreach($filterins as $filterin){
            $last_time = $filterin->end_time - time();
//            echo $last_time.'<br>';
            if($last_time < 604800 && $last_time > 0){

                DB::beginTransaction();
                echo $filterin->id;
                $filterin = Filterin::find($filterin->id);
                $filterin->has_notice = 1;
                $filterin->save();
                $this->forcustomer($filterin->mount->machine->name,$filterin->commodity->name,$filterin);

                //查询该分销商是否有微信派单人
                $count = Work::where('section_id',$filterin->mount->section_id)->where('paidan',1)->count();
                if($count != 0){//有则发送模板消息
                    $work = Work::where('section_id',$filterin->mount->section_id)->where('paidan',1)->first();
                    $this->forworker($work->openid,$filterin->mount->machine->name,$filterin->commodity->name,$filterin);
                }


                DB::commit();

            }
        }
    }

    public function shiyong_notice(){
        $time = time();
        $mounts = Mount::where('shiyong_notice','0')->where('state',1)->get();
        foreach($mounts as $mount){
            if($time - $mount->shiyong_start > 2592000){
                DB::beginTransaction();
                $this->shiyong_forcustomer($mount->machine->name,$mount);
                //查询该分销商是否有微信派单人
                $count = Work::where('section_id',$mount->section_id)->where('paidan',1)->count();
                if($count != 0){//有则发送模板消息
                    $work = Work::where('section_id',$mount->section_id)->where('paidan',1)->first();
                    $this->shiyong_forworker($work->openid,$mount->machine->name,$mount);
                }


                $this_mount = Mount::find($mount->id);
                $this_mount->shiyong_notice = 1;
                $this_mount->save();


                $c_user = User::where('permissions','{"city":1}')->where('city',$mount->city)->first();
                $c_user->shiyong_notice = 1;
                $c_user->save();

                $s_user = User::where('permissions','{"section":1}')->where('area',$mount->section_id)->first();
                $s_user->shiyong_notice = 1;
                $s_user->save();


                DB::commit();
            }

        }
    }




    function sms(){

    }

    function returnSquarePoint($lng, $lat,$distance = 5){
        define(EARTH_RADIUS, 6371);//地球半径，平均半径为6371km
        $dlng =  2 * asin(sin($distance / (2 * EARTH_RADIUS)) / cos(deg2rad($lat)));
        $dlng = rad2deg($dlng);

        $dlat = $distance/EARTH_RADIUS;
        $dlat = rad2deg($dlat);

        return array(
            'left-top'=>array('lat'=>$lat + $dlat,'lng'=>$lng-$dlng),
            'right-top'=>array('lat'=>$lat + $dlat, 'lng'=>$lng + $dlng),
            'left-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng - $dlng),
            'right-bottom'=>array('lat'=>$lat - $dlat, 'lng'=>$lng + $dlng)
        );
    }

    /**
     *  @desc 根据两点间的经纬度计算距离
     *  @param float $lat 纬度值
     *  @param float $lng 经度值
     */
    function getDistance($lat1, $lng1, $lat2, $lng2)
    {
        $earthRadius = 6367000; //approximate radius of earth in meters

        /*
          Convert these degrees to radians
          to work with the formula
        */

        $lat1 = ($lat1 * pi() ) / 180;
        $lng1 = ($lng1 * pi() ) / 180;

        $lat2 = ($lat2 * pi() ) / 180;
        $lng2 = ($lng2 * pi() ) / 180;

        /*
          Using the
          Haversine formula

          http://en.wikipedia.org/wiki/Haversine_formula

          calculate the distance
        */

        $calcLongitude = $lng2 - $lng1;
        $calcLatitude = $lat2 - $lat1;
        $stepOne = pow(sin($calcLatitude / 2), 2) + cos($lat1) * cos($lat2) * pow(sin($calcLongitude / 2), 2);
        $stepTwo = 2 * asin(min(1, sqrt($stepOne)));
        $calculatedDistance = $earthRadius * $stepTwo;

        return $stepTwo.'+'.round($calculatedDistance);
    }


    public function forworker($openid,$mount_name,$commodity_name,$filterin){

        $data[0] = '你的客户您有一个滤芯即将到期';

        $data[1] = $mount_name.'-'.$commodity_name;
        $data[2] = date('Y.m.d',$filterin->start_time).'至'.date('Y.m.d',$filterin->end_time);
        $data[3]= '客户姓名:'.$filterin->mount->mount_name.'   客户电话:'.$filterin->mount->mount_mobile.'   请您及时联系更换滤芯';
        $url = '';

        Template::newone($openid,$data,$url,4);
    }

    public function forcustomer($mount_name,$commodity_name,$filterin){

        $data[0] = '尊敬的客户您有一个滤芯即将到期';

        $data[1] = $mount_name.'-'.$commodity_name;
        $data[2] = date('Y.m.d',$filterin->start_time).'至'.date('Y.m.d',$filterin->end_time);
        $data[3]= '请您及时提交换芯工单更换滤芯';
        $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxc64f995bebe39161&redirect_uri=http%3a%2f%2fcrm.leaderphos.com%2fdiscern&response_type=code&scope=snsapi_userinfo&state=mount#wechat_redirect';

        Template::newone($filterin->mount->customer->openid,$data,$url,4);
    }
    public function shiyong_forworker($openid,$mount_name,$mount){

        $data[0] = '你的客户您有一个30天试用装机即将到期';

        $data[1] = $mount_name;
        $data[2] = '到期时间:'.date('Y.m.d',$mount->shiyong_start+2592000);
        $data[3]= '客户姓名:'.$mount->mount_name.'   客户电话:'.$mount->mount_mobile.'   请您及时联系';
        $url = '';

        Template::newone($openid,$data,$url,4);
    }

    public function shiyong_forcustomer($mount_name,$mount){

        $data[0] = '尊敬的客户您有一个30天试用装机即将到期';

        $data[1] = $mount_name;
        $data[2] = '到期时间:'.date('Y.m.d',$mount->shiyong_start+2592000);
        $data[3]= '请您及时提交签约';
        $url = '';

        Template::newone($mount->customer->openid,$data,$url,4);
    }


//    public function start($path,$code){
//
//        $dir = dirname(dirname(dirname(__FILE__))); //取得当前文件的上一层目录名，结果：D:\
//        $file = $dir.'/public/temp.jpg';
//        $file2 = $path;
//        $file3 = $dir.'/public/pic/'.$code.'.jpg';
//        $image_1 = imagecreatefromjpeg($file);
//        $image_2 = imagecreatefromjpeg($file2);
//        //创建一个和人物图片一样大小的真彩色画布（ps：只有这样才能保证后面copy装备图片的时候不会失真）
//        $image_3 = imageCreatetruecolor(imagesx($image_1),imagesy($image_1));
//        //为真彩色画布创建白色背景，再设置为透明
//        $color = imagecolorallocate($image_3, 250, 255, 255);
//        imagefill($image_3, 0, 0, $color);
//        imageColorTransparent($image_3, $color);
//        //首先将人物画布采样copy到真彩色画布中，不会失真
////        imagecopyresampled($image_3,$image_1,0,0,0,0,imagesx($image_1),imagesy($image_1),imagesx($image_1),imagesy($image_1));
////        //再将装备图片copy到已经具有人物图像的真彩色画布中，同样也不会失真
////        imagecopymerge($image_3,$image_2, 0,320,0,0,imagesx($image_2),imagesy($image_2), 100);
//        //将画布保存到指定的gif文件
//        $image_4 = imageCreatetruecolor(550,550);
//        imagecopyresampled($image_4,$image_2,0,0,0,0,550,550,600,600);
////        imagecopy($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1));
//        imagecopy($image_1, $image_4, 670, 80, 0, 0, 380, 380);
//        $text_color = ImageColorAllocate($image_1, 200, 200, 200);      //设置文字颜色为黑色
//        imagestring($image_1, 10, 810, 480, $code, $text_color);        //输出文章标题
//        imagejpeg($image_1, $file3);
//    }
//
//
//    public function get_code($true){
////        $pub = Pub::find(1);
//        if (Cache::has('token'))
//        {
//            //
//            $value = Cache::get('token');
//        }else{
//            $value =  Wechat::get_access_token('wxc64f995bebe39161','60e3408c857a4b4a0d4e891dac61c22e');
//            Cache::put('token', $value, 240);
//        }
//        $arr['ticket'] = Wechat::get_pic($value,$true,1,false);
//        if($arr['ticket'] == 'error'){
//            $value =  Wechat::get_access_token('wxc64f995bebe39161','60e3408c857a4b4a0d4e891dac61c22e');
//            Cache::put('token', $value, 240);
//            $arr['ticket'] = Wechat::get_pic($value,$true,1,false);
//        }
//        return $arr['ticket'];
//    }
//
//    public function down(){
//        for($i = 11825 ; $i<=12000 ; $i++) {
////        $i = 10790;
//            $path = $this->get_code($i);
//            $this->start($path, $i);
//        }
//    }
    public function check_dom(){

        for($i =1 ;$i<=40 ;$i++){
            $domain = $this->shencheng();

            $xml_arr=$this->query($domain);
            echo $domain.$this->show($xml_arr).'<br>';
        }
    }



//查询接口
    public function query($domain) {
        $do = "http://panda.www.net.cn/cgi-bin/check.cgi?area_domain=" . $domain;
        $xml_data = file_get_contents($do);
        $xml_arr = (array) simplexml_load_string($xml_data);
        return $xml_arr;
    }
//显示接口
    function show($result_arr){
        $returncode=$result_arr['returncode'];
        $key=$result_arr['key'];
        $original=$result_arr['original'];
        $status=  substr($original,0,3);
        //申明返回值
        $result;
        if($status=="210"){
            return "可以注册-----";
        }
    }

    public function shencheng(){
        $ychar="0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
        $ychar="a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
        $list=explode(",",$ychar);
        for($i=0;$i<1;$i++){
            $randnum=rand(0,25);
            $password.=$list[$randnum];
        }
        $domain = $password.'chen'.'.cn';
        return $domain;
    }

    public function dom($domain){

        $con1 = ' http://www.checkdomain.com/cgi-bin/checkdomain.pl?domain='.$domain;
        $html = file_get_contents($con1);
        $checked = strpos($html,"has already been registered");


        if( $checked <> null ) {
            return false;
        }else{
            return true;
        }
    }
    public function send_sms($mobile,$code){
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );
        $smsapi = "http://www.smsbao.com/"; //短信网关
        $user = "leaderphos"; //短信平台帐号
        $pass = md5("leidi2012"); //短信平台密码
        $content="感谢您使用雷谛净水机，由于微信系统升级，请重新绑定您的净水机。微信关注“雷谛科技”，发送验证码“".$code."”到官方微信";//要发送的短信内容
        $phone = $mobile;
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
        return $result;
    }

    public function get_old_and_sendsms(){
//        $olds = Mount::where('type','old')->get();
//        foreach($olds as $old){
////            echo $old->mount_mobile.'<br>';
//            $thisold = Mount::find($old->id);
//            $result = $this->send_sms($old->mount_mobile,$old->bangding);
//            $thisold->send_state = $result;
//            echo $result.'<br>';
//        }
    }


    public function send_img(){
//        $pictures = Picture::where('id','>',59)->get();
//        foreach($pictures as $picture){
//            if($picture->mount_id){
        $mount = Mount::find('3564');
        $mount->send_state = 1;
        $mount->save();
//            }

//        }



//        $Path = 'http://7vij71.com2.z0.glb.qiniucdn.com/leaderphos/';
//        $orders = Order::all();
//        $i =0;
//        foreach($orders as $order){
//            $time = rand(1397377812,1428477896);
//            $data = date("Y-m-d H:i:s",$time);
//            if($order->pic1 != ''){
//                $pic = explode('uploads/',$order->pic1);
//                $newpic = $Path.$pic[1];
//                $mount = Mount::where('mount_mobile',$order->tel)->first();
//                $arr[$i]['mount_id'] = $mount->id;
//                $arr[$i]['path'] = $newpic;
//                $arr[$i]['created_at'] = $data;
//                $i++;
//            }
//            if($order->pic2 != ''){
//                $pic = explode('uploads/',$order->pic2);
//                $newpic = $Path.$pic[1];
//                $arr[$i]['mount_id'] = $mount->id;
//                $arr[$i]['path'] = $newpic;
//                $arr[$i]['created_at'] = $data;
//                $i++;
//            }
//            if($order->pic3 != ''){
//                $pic = explode('uploads/',$order->pic3);
//                $newpic = $Path.$pic[1];
//                $arr[$i]['mount_id'] = $mount->id;
//                $arr[$i]['path'] = $newpic;
//                $arr[$i]['created_at'] = $data;
//                $i++;
//            }
//            if($order->pic4 != ''){
//                $pic = explode('uploads/',$order->pic4);
//                $newpic = $Path.$pic[1];
//                $arr[$i]['mount_id'] = $mount->id;
//                $arr[$i]['path'] = $newpic;
//                $arr[$i]['created_at'] = $data;
//                $i++;
//            }
//        }
////        var_dump($arr);
//        DB::table('pictures')->insert($arr);
    }



    public function start($path,$code){

        $dir = dirname(dirname(dirname(__FILE__))); //取得当前文件的上一层目录名，结果：D:\
        $file = $dir.'/public/temp.jpg';
        $file2 = $path;
        $file3 = $dir.'/public/pic/'.$code.'.jpg';
        $image_1 = imagecreatefromjpeg($file);
        $image_2 = imagecreatefromjpeg($file2);
        //创建一个和人物图片一样大小的真彩色画布（ps：只有这样才能保证后面copy装备图片的时候不会失真）
        $image_3 = imageCreatetruecolor(imagesx($image_1),imagesy($image_1));
        //为真彩色画布创建白色背景，再设置为透明
        $color = imagecolorallocate($image_3, 250, 255, 255);
        imagefill($image_3, 0, 0, $color);
        imageColorTransparent($image_3, $color);
        //首先将人物画布采样copy到真彩色画布中，不会失真
//        imagecopyresampled($image_3,$image_1,0,0,0,0,imagesx($image_1),imagesy($image_1),imagesx($image_1),imagesy($image_1));
//        //再将装备图片copy到已经具有人物图像的真彩色画布中，同样也不会失真
//        imagecopymerge($image_3,$image_2, 0,320,0,0,imagesx($image_2),imagesy($image_2), 100);
        //将画布保存到指定的gif文件
        $image_4 = imageCreatetruecolor(550,550);
        imagecopyresampled($image_4,$image_2,0,0,0,0,550,550,600,600);
//        imagecopy($image_3, $image_1, 0, 0, 0, 0, imagesx($image_1), imagesy($image_1));
        imagecopy($image_1, $image_4, 670, 80, 0, 0, 380, 380);
        $text_color = ImageColorAllocate($image_1, 200, 200, 200);      //设置文字颜色为黑色
        imagestring($image_1, 10, 810, 480, $code, $text_color);        //输出文章标题
        imagejpeg($image_1, $file3);
    }


    public function get_code($true){
//        $pub = Pub::find(1);
        if (Cache::has('token'))
        {
            //
            $value = Cache::get('token');
        }else{
            $value =  Wechat::get_access_token('wxc64f995bebe39161','60e3408c857a4b4a0d4e891dac61c22e');
            Cache::put('token', $value, 240);
        }
        $arr['ticket'] = Wechat::get_pic($value,$true,1,false);
        if($arr['ticket'] == 'error'){
            $value =  Wechat::get_access_token('wxc64f995bebe39161','60e3408c857a4b4a0d4e891dac61c22e');
            Cache::put('token', $value, 240);
            $arr['ticket'] = Wechat::get_pic($value,$true,1,false);
        }
        return $arr['ticket'];
    }

    public function down(){
        for($i = 12259 ; $i<=12375 ; $i++) {
//        $i = 10790;
            $path = $this->get_code($i);
            $this->start($path, $i);
        }
    }
    public function upload_image(){
        require app_path().'/lib/qiniu/rs.php';
        require app_path().'/lib/qiniu/io.php';
        $pics = Picture::where('change',0)->take(5)->get();
        foreach($pics as $pic){
            $contents = @file_get_contents($pic->path);
            //
            $uploadfile = $this->random(5).time().'.jpg';
            $result = $this->upPicTo7niu($contents,'com',$uploadfile,'aebo');


            $this_pic = Picture::find($pic->id);
            $this_pic->path = "http://aebo.qiniudn.com/".$result['key'];
            $this_pic->change = 1;
            $this_pic->save();


        }
    }
    function random($length)
    {
        $hash = 'CR-';
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
        $max = strlen($chars) - 1;
        mt_srand((double)microtime() * 1000000);
        for($i = 0; $i < $length; $i++)
        {
            $hash .= $chars[mt_rand(0, $max)];
        }
        return $hash;
    }
    /**
     *上传图片至七牛云
     *$path 图片地址
     *$dirname 在七牛云上的文类名称
     *$filename 文件保存名称
     *$bucket 你的七牛云域名称
     */
    function upPicTo7niu($contents,$dirname,$filename,$bucket){

        $storename = $dirname."/".$filename;
        $bu = $bucket.":".$storename;
        $accessKey = 'FWdy0abUDmanFns5ZArKEHjRl2e5hXeZVsLKSU7M';
        $secretKey = 'zuHKtuuL888TuuavvzbyWnGnytjW33zI1mrAql12';

        Qiniu_SetKeys($accessKey, $secretKey);
        $putPolicy = new \Qiniu_RS_PutPolicy($bu);
        $upToken = $putPolicy->Token(null);
        $putExtra = new \Qiniu_PutExtra();
        $putExtra->Crc32 = 1;
        list($ret, $err) = Qiniu_Put($upToken, $storename, $contents, $putExtra);
        return $ret;
    }


}
